var hasLoaded = false;

var NUMBER_OF_PICTURES = 3;
var PICTURES_ID_PREFIX = "picGalleryNoScript_";
var PICTURES_LINK_ID_PREFIX = "pictureLink_";

var currentPic = 0;

//var LOADING_DIV = "picGallery_loading";
var NEXT_DIV = "next";
var BACK_DIV = "back";
var NAVBOX_DIV = "navBox";
//var THUMBNAILS_DIV = "thumbnails";

// pic Gallery colours
//var currentPicColor = "/Modules/PSGallery/number_on.jpg";
//var unselectedColor = "/Modules/PSGallery/number_off.jpg";
var currentPicColor = "#6E6E6E";
var unselectedColor = "#333333";
var deadLinkColor = "#ffffff";

function init() 
{    
	hasLoaded = true;
	//alert('co vao init');
	showDiv(0); 
	//alert('da xy ly qua ham showdiv');
	//document.getElementById('ctl00_Detail1_lbnow').innerHTML = currentPic + 1;
	//document.getElementById(NAVBOX_DIV).style.display = 'block';
//	document.getElementById(PICTURES_LINK_ID_PREFIX + currentPic).style.background = currentPicColor;	
}

function setNoOfImages(noOfImages) 
{
    
	NUMBER_OF_PICTURES = noOfImages;
}

function doBgColor() 
{
	for(var i = 0; i < NUMBER_OF_PICTURES; i++) 
	{
		document.getElementById(PICTURES_LINK_ID_PREFIX + i).style.background = unselectedColor;
	}		
	document.getElementById(PICTURES_LINK_ID_PREFIX + currentPic).style.background = currentPicColor;
}

function doNextColor() 
{
	document.getElementById(BACK_DIV).style.background = unselectedColor;
	if(currentPic < (NUMBER_OF_PICTURES - 1)) 
	{
		document.getElementById(NEXT_DIV).style.background = unselectedColor;
	} 
	else 
	{
		document.getElementById(NEXT_DIV).style.background = deadLinkColor;
	}		
}

function doBackColor()
{
	document.getElementById(NEXT_DIV).style.background = unselectedColor;

	if(currentPic > 0) 
	{
		document.getElementById(BACK_DIV).style.background = unselectedColor;
	} 
	else 
	{
		document.getElementById(BACK_DIV).style.background = deadLinkColor;
	}		
}

function showDiv(nDiv) 
{	
    
	for(var i = 0; i < NUMBER_OF_PICTURES; i++) 
	{			
		var buttonid = i;		
		var id = PICTURES_ID_PREFIX + i;	
		var node = document.getElementById(id);
		//alert(node + 'i=' + i + "   ndiv="+ nDiv);
		if(node && i==nDiv) 
		{		    
			node.style.display='block';		
			node.style.visibility='visible';						
			currentPic = i;			
			document.getElementById(PICTURES_LINK_ID_PREFIX + currentPic).style.background = currentPicColor;
		}

		else if(node) 
		{		    
			node.style.display='none';
			node.style.visibility='hidden';
		}				
	}
	//document.getElementById('ctl00_Detail1_lbnow').innerHTML = currentPic + 1;
	
}

function showDivNext() 
{
    //alert(currentPic);
	if(currentPic < (NUMBER_OF_PICTURES - 1)) 
	{
		showDiv(currentPic + 1);	
		doBgColor();	
		doNextColor();
	}   
	
}

function showDivPrev() 
{
//alert(currentPic);
	if(currentPic > 0) 
	{
		showDiv(currentPic - 1);
		doBgColor();	
		doBackColor();		
	}
	
}

function ColorOver(o) 
{
	o.style.backgroundColor = currentPicColor;	
}

function ColorOut(o) 
{
	o.style.backgroundColor = unselectedColor;
	document.getElementById(PICTURES_LINK_ID_PREFIX + currentPic).style.background = currentPicColor;
}

if (document.getElementById) 
{
	document.onLoad = init();
}
